{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'max_depth': [6, 7, 8], 'min_child_weight': [4, 5, 6]}\n",
      "Best: -0.587481 using {'max_depth': 6, 'min_child_weight': 4}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Text(0,0.5,u'Log Loss')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAELCAYAAADz6wBxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xt8XGW97/HPL5N7mjbpPW2atlQuLVBbKC2ClF6CFNnWjaCC4mvDPoiibLwcFDjurRtEhe05iiK6UQQ9chWUvYsHBBJqq9zb2hYot1Jomrb0kja9pbn/zh9rJZ1MJ8kkk8n1+3695pV1n2cmk/nmedZ61mPujoiISHel9XUBRERkYFOQiIhIUhQkIiKSFAWJiIgkRUEiIiJJUZCIiEhSFCQiIpIUBYmIiCRFQSIiIklJ7+sC9IbRo0f7lClT+roYIiIDyurVq3e7+5jOthsSQTJlyhRWrVrV18UQERlQzGxzItupaUtERJKiIBERkaQoSEREJCkpDRIzW2Jmb5rZRjO7Ps76y8xsl5mtDR9XRK271cxeDR+fjlr+azNbZ2brzewRMxuWytcgIiIdS1mQmFkEuAM4D5gBXGJmM+Js+pC7zwofd4X7ng+cAswC5gHfMLPh4fZfc/cPuvtMoAK4OlWvQUREOpfKGslcYKO7b3L3euBB4OMJ7jsDWOHuje5+CFgHLAFw9/0AZmZADqCRuURE+lAqg2QisCVqvjJcFuvCqGaqSeGydcB5ZpZrZqOBhUDLOszsHuB94ATg9pSU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6dOn8/zzz3fr+TuTSI3kD0CTmX0A+DUwFbg/JaURkSFvsAZJMmKDJFFf+cpXWLJkCW+88Qbr1q1j+vTpKShdYpf/NoeX8l4A3Obut5vZ31NSGhHpV2587DU2bNvfo8ecMWE43/nYie2uv/7663nnnXeYNWsW55xzDmPHjuX3v/89dXV1XHDBBdx4440cOnSIT33qU1RWVtLU1MS//du/sWPHDrZt28bChQsZPXo0y5cvj3v8YcOG8eUvf5mysjIKCwv5/ve/zze/+U0qKiq47bbbWLp0Ke+99x6f+9znOHToEAA/+9nPOOOMM3j00Ue54447ePrpp3n//fc5++yzWblyJePHjz/qeQ4fPszll1/Ohg0bmD59OocPH25d99RTT/Gd73yHuro6pk2bxj333MOwYcOYMmUKn/70p1vLfv/997Nz506WLVvGihUruPnmm/nDH/4AwMMPP8yXvvQlqqur+fWvf81ZZ53V5vn379/PypUr+c1vfgNAZmYmmZmZif+iuiCRGkmDmV0C/BPBXXch6OchItLjbrnlFqZNm8batWs555xzePvtt3nppZdYu3Ytq1evZuXKlfz5z39mwoQJrFu3jldffZUlS5ZwzTXXMGHCBJYvX95uiAAcOnSIBQsWsHr1avLz8/nXf/1Xnn76aR599FG+/e1vAzB27Fiefvpp1qxZw0MPPcQ111wDwAUXXMD48eO54447+PznP8+NN94YN0QAfvGLX5Cbm8v69ev51re+xerVqwHYvXs3N998M2VlZaxZs4Y5c+bwox/9qHW/4cOH89JLL3H11Vfz1a9+lTPOOIOlS5fywx/+kLVr1zJt2jQAGhsbeemll7jtttu48cYbAdi2bRsf/ehHAdi0aRNjxozh8ssvZ/bs2VxxxRWtwdjTEqmRXA58Efieu79rZlOBe1NSGhHpVzqqOfSGp556iqeeeorZs2cDcPDgQd5++23OOussrr32Wq677jr+4R/+4aj/xjuSmZnJkiVLADj55JPJysoiIyODk08+mffeew8IOmVeffXVrF27lkgkwltvvdW6/+23385JJ53E6aefziWXXNLu86xcubI1gGbOnMnMmTMBeOGFF9iwYQNnnnkmAPX19XzoQx9q3a/lmJdccglf+9rX2j3+Jz7xCQBOPfXU1nJPmDCBxx9/HAiCZs2aNdx+++3MmzePr3zlK9xyyy1897vfTfi9SlSnQRKOH3INgJkVAvnufkuPl0REJIa7c8MNN/CFL3zhqHWrV6/m8ccf54YbbuAjH/lIa22iMxkZGa2Xu6alpZGVldU63dgY3Bv2xz/+MePGjWPdunU0NzeTnZ3duv/WrVtJS0tjx44dNDc3k5bWfsNOvMtq3Z1zzjmHBx54oNN9Orost6XckUiktdzRiouLKS4uZt68eQBcdNFF3HJLar66E7lq6y9mNtzMRhLc3v0eM/tRZ/uJiHRHfn4+Bw4cAODcc8/l7rvv5uDBg0DwJb5z5062bdtGbm4ul156Kddeey1r1qw5at9k7Nu3j6KiItLS0vjd735HU1MTEPyXf/nll3P//fczffr0Nk1SsebPn899990HwKuvvsr69esBOP3003n22WfZuHEjADU1NW1qPA899FDrz5aaSnde1/jx45k0aRJvvvkmAOXl5cyYMaNLx0hUIk1bI9x9fzgM7j3u/h0zW5+S0ojIkDdq1CjOPPNMTjrpJM477zw+85nPtH6hDhs2jHvvvZeNGzfyjW98g7S0NDIyMvjFL34BwJVXXsl5551HUVFRh+dJOvOlL32JCy+8kIcffpiFCxeSl5cHwPe//33OOusszjrrLGbNmsVpp53G+eefH/dqqKuuuorLL7+cmTNnMmvWLObOnQvAmDFj+M1vfsMll1xCXV1w8/Obb76Z4447DoC6ujrmzZtHc3Nza63l4osv5vOf/zw//elPeeSRR9ot97Zt27jiiitam7duv/12PvvZz1JfX88xxxzDPffc0+33pCOd3mvLzF4BPkIwVsi33P1lM1sfjiEyIOheWyKJe/3111N2mah0bMqUKaxatYrRo0f3+nPH+7335L22biK4g+87YYgcQxfHBhERkcErkZPtDwMPR81vAi5MZaFERJI1b9681qajFr/73e84+eSTe/R5nnzySa677ro2y6ZOncqjjz7a5WO1XH010HQaJGZWDNwOnEkwVO7fgK+4e2WKyyYi0m0vvvhirzzPueeey7nnntsrz9VfJdK0dQ/ByIYTgIkE46yn5oyN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ure.Figure at 0x130392b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#对MAX_DEPTH 和 min_chiild_weight进行调优\n",
    "from xgboost import XGBClassifier\n",
    "import xgboost as xgb\n",
    "import pickle\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "\n",
    "from sklearn.metrics import log_loss\n",
    "\n",
    "from matplotlib import pyplot\n",
    "import seaborn as sns\n",
    "%matplotlib inline\n",
    "\n",
    "#读取数据\n",
    "dbpath = \"./data/\"\n",
    "train = pd.read_csv(dbpath +\"RentListingInquries_FE_train.csv\")\n",
    "\n",
    "y_train = train['interest_level']\n",
    "X_train = train.drop([\"interest_level\",\"Year\"],axis=1)\n",
    "                    \n",
    "kfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=3)\n",
    "#设定max_depth min_child_weight参数\n",
    "max_depth = [6,7,8]\n",
    "min_child_weight = [4,5,6]\n",
    "param_test = dict(max_depth=max_depth, min_child_weight=min_child_weight)\n",
    "n_estimators =235\n",
    "print(param_test)\n",
    "''' 结果保存人文件中，次处代码可以不用执行了。\n",
    "\n",
    "xgbc = XGBClassifier(\n",
    "        learning_rate =0.1,\n",
    "        n_estimators=n_estimators,  #第一轮参数调整得到的n_estimators最优值\n",
    "        max_depth=5,\n",
    "        min_child_weight=1,\n",
    "        gamma=0,\n",
    "        subsample=0.3,\n",
    "        colsample_bytree=0.8,\n",
    "        colsample_bylevel = 0.7,\n",
    "        objective= 'multi:softprob',\n",
    "        seed=3)\n",
    "gsearch = GridSearchCV(xgbc, param_grid = param_test, scoring='neg_log_loss',n_jobs=-1, cv=kfold)\n",
    "gsearch.fit(X_train , y_train)\n",
    "gsearch.grid_scores_, gsearch.best_params_,     gsearch.best_score_\n",
    "\n",
    "#将结果存入文件中\n",
    "pd.DataFrame(gsearch.cv_results_).to_csv('RLI_maxdepth_minchildweight.csv')\n",
    "fparamgrid = open(\"param_grid.data\",\"wb\")\n",
    "pickle.dump(gsearch.best_params_,fparamgrid,-1)\n",
    "fparamgrid.close()\n",
    "'''\n",
    "#读取结果文件\n",
    "fparamgrid = open(\"param_grid.data\",\"rb\")\n",
    "best_params = pickle.load(fparamgrid)\n",
    "cv_results = pd.read_csv(\"RLI_maxdepth_minchildweight.csv\")\n",
    "fparamgrid.close()\n",
    "\n",
    "\n",
    "# summarize results\n",
    "#以下代码从结果文件中读结果再运行\n",
    "print(\"Best: %f using %s\" % (gsearch.best_score_, gsearch.best_params_))\n",
    "test_means = cv_results[ 'mean_test_score' ]\n",
    "test_stds = cv_results[ 'std_test_score' ]\n",
    "train_means = cv_results[ 'mean_train_score' ]\n",
    "train_stds = cv_results[ 'std_train_score' ]\n",
    "\n",
    "\n",
    "# plot results\n",
    "test_scores = np.array(test_means).reshape(len(max_depth), len(min_child_weight))\n",
    "train_scores = np.array(train_means).reshape(len(max_depth), len(min_child_weight))\n",
    "\n",
    "for i, value in enumerate(max_depth):\n",
    "    pyplot.plot(min_child_weight, -test_scores[i], label= 'test_max_depth:'   + str(value))\n",
    "#for i, value in enumerate(min_child_weight):\n",
    "#    pyplot.plot(max_depth, train_scores[i], label= 'train_min_child_weight:'   + str(value))\n",
    "    \n",
    "pyplot.legend()\n",
    "pyplot.xlabel( 'max_depth' )                                                                                                      \n",
    "pyplot.ylabel( 'Log Loss' )\n",
    "#pyplot.savefig('max_depth_vs_min_child_weght_1.png' )\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
